import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/shop',
    component: Layout,
    meta: {
      title: "优选商城",
      icon: 'el-icon-shopping-cart-full',
    },
    children: [
      {
        path: 'category',
        name: 'shop-category',
        component: () => import('@/views/shop/category/index'),
        meta: {
          title: "商品分类",
        }
      },
      {
        path: 'product',
        name: 'shop-product',
        component: () => import('@/views/shop/product/index'),
        meta: {
          title: "商品管理",
        }
      },
      {
        path: 'order',
        name: 'shop-order',
        component: () => import('@/views/shop/order/index'),
        meta: {
          title: "订单管理",
        }
      },
      {
        path: 'order/detail/:id',
        name: 'shop-order-detail',
        component: () => import('@/views/shop/order/detail'),
        meta: {
          title: "订单详情",
        },
        hidden: true
      },
      {
        path: 'refund',
        name: 'shop-refund',
        component: () => import('@/views/shop/refund/index'),
        meta: {
          title: "退款管理",
        }
      }
    ]
  },
  {
    path: '/officeShop',
    component: Layout,
    meta: {
      title: "办公用品",
      icon: 'el-icon-shopping-cart-full',
    },
    children: [
      {
        path: 'category',
        name: 'water-category',
        component: () => import('@/views/officeShop/category/index'),
        meta: {
          title: "商品分类",
        }
      },
      {
        path: 'product',
        name: 'water-product',
        component: () => import('@/views/officeShop/product/index'),
        meta: {
          title: "商品管理",
        }
      },
      {
        path: 'order',
        name: 'water-order',
        component: () => import('@/views/officeShop/order/index'),
        meta: {
          title: "订单管理",
        }
      },
      {
        path: 'order/detail/:id',
        name: 'water-order-detail',
        component: () => import('@/views/officeShop/order/detail'),
        meta: {
          title: "订单详情",
        },
        hidden: true
      },
      {
        path: 'refund',
        name: 'water-refund',
        component: () => import('@/views/officeShop/refund/index'),
        meta: {
          title: "退款管理",
        }
      }
    ]
  },
  {
    path: '/waterShop',
    component: Layout,
    meta: {
      title: "大桶水配送",
      icon: 'el-icon-shopping-cart-full',
    },
    children: [
      {
        path: 'category',
        name: 'water-category',
        component: () => import('@/views/waterShop/category/index'),
        meta: {
          title: "商品分类",
        }
      },
      {
        path: 'product',
        name: 'water-product',
        component: () => import('@/views/waterShop/product/index'),
        meta: {
          title: "商品管理",
        }
      },
      {
        path: 'order',
        name: 'water-order',
        component: () => import('@/views/waterShop/order/index'),
        meta: {
          title: "订单管理",
        }
      },
      {
        path: 'order/detail/:id',
        name: 'water-order-detail',
        component: () => import('@/views/waterShop/order/detail'),
        meta: {
          title: "订单详情",
        },
        hidden: true
      },
      {
        path: 'refund',
        name: 'water-refund',
        component: () => import('@/views/waterShop/refund/index'),
        meta: {
          title: "退款管理",
        }
      }
    ]
  },
  {
    path: '/officeBuilding',
    component: Layout,
    meta: {
      title: "写字楼",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'template',
        name: 'building-template',
        component: () => import('@/views/officeBuilding/template'),
        meta: {
          title: "楼盘维护",
        }
      },
      {
        // 楼盘维护
        path: 'list',
        name: 'building-list',
        component: () => import('@/views/officeBuilding/list'),
        meta: {
          title: "楼盘维护",
        }
      }
    ]
  },
  {
    path: '/config',
    component: Layout,
    meta: {
      title: "配置管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/banner',
        name: 'banner',
        component: () => import('@/views/banner/index.vue'),
        meta: {
          title: "轮播管理",
        }
      },
      {
        path: '/category',
        name: 'category',
        component: () => import('@/views/category/index.vue'),
        meta: {
          title: "分类管理",
        }
      },
      {
        path: '/district',
        name: 'district',
        component: () => import('@/views/district/index.vue'),
        meta: {
          title: "区域管理",
        }
      },
      {
        path: '/policy',
        name: 'policy',
        component: () => import('@/views/system/policy/index.vue'),
        meta: {
          title: "协议配置",
        }
      },
      {
        path: '/wx',
        name: 'wx',
        component: () => import('@/views/system/wxConfig/index.vue'),
        meta: {
          title: "微信配置",
        }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    meta: {
      title: "会员管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/member',
        name: 'member',
        component: () => import('@/views/member/index.vue'),
        meta: {
          title: "会员管理",
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
